package com.haoting.mamba.player.service.impl;

import com.haoting.mamba.player.entity.PlayerBasicdateEntity;
import com.haoting.mamba.player.entity.PlayerInformationEntity;
import com.haoting.mamba.player.service.PlayerInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.Query;

import com.haoting.mamba.player.dao.PlayerAdvancedDao;
import com.haoting.mamba.player.entity.PlayerAdvancedEntity;
import com.haoting.mamba.player.service.PlayerAdvancedService;


@Service("playerAdvancedService")
public class PlayerAdvancedServiceImpl extends ServiceImpl<PlayerAdvancedDao, PlayerAdvancedEntity> implements PlayerAdvancedService {

    @Autowired
    PlayerInformationService playerInformationService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PlayerAdvancedEntity> wrapper =  new QueryWrapper<>();
        if(!String.valueOf(params.get("query")).equals("")){
            wrapper.eq("stage",params.get("query"));
        }
        if(!String.valueOf(params.get("key")).equals("")){
            PlayerInformationEntity one = playerInformationService.getOne(new QueryWrapper<PlayerInformationEntity>()
                    .like("name", params.get("key")));
            String playerId = one.getId();
            wrapper.like("player_id",playerId);
        }
        IPage<PlayerAdvancedEntity> page = this.page(
                new Query<PlayerAdvancedEntity>().getPage(params),
                wrapper
        );

        for (int i=0;i<page.getRecords().size();i++){
            PlayerInformationEntity byId = playerInformationService.getById(page.getRecords().get(i).getPlayerId());
            String name = byId.getName();
            page.getRecords().get(i).setPlayerId(name);
        }

        return new PageUtils(page);
    }

}